//
//  CarCollectionViewCell.m
//  MansApp
//
//  Created by lanou3g on 15/7/16.
//  Copyright (c) 2015年 ACH. All rights reserved.
//

#import "CarCollectionViewCell.h"
#import "CarModel.h"
@implementation CarCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        CGFloat width = kWidth / 3 - kP6width(10);
        CGFloat height = (kHeight - kP6Height(70)) / 4 - kP6Height(10);
        
        self.oneImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 20, width, height)];
        self.oneImageView.tag =  100;
        self.oneImageView.image = [UIImage imageNamed:@"page"];
        
        self.twoImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10 + self.oneImageView.bounds.size.width, 20, width, height)];
        self.twoImageView.tag = 101;
        self.twoImageView.image = [UIImage imageNamed:@"page"];
        
         self.threeImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.twoImageView.frame.origin.x + self.twoImageView.bounds.size.width + 5, 20, width, height)];
        self.threeImageView.image = [UIImage imageNamed:@"page"];
        self.threeImageView.tag = 102;
        self.fourImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, self.oneImageView.frame.origin.y +    self.oneImageView.bounds.size.height + 5, width, height)];
        self.fourImageView.tag = 103;
        self.fourImageView.image = [UIImage imageNamed:@"page"];
         self.fiveLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.twoImageView.frame.origin.x, self.oneImageView.frame.origin.y + self.oneImageView.bounds.size.height + 5,  2 * width + kP6width(5), height)];
        
        self.fiveLabel.text = @"骏车美女";
        self.fiveLabel. textColor = [UIColor whiteColor];
        self.fiveLabel.font =  [UIFont fontWithName:@"Courier-BoldOblique" size:22];
        self.fiveLabel.textAlignment = NSTextAlignmentCenter;
        self.fiveLabel.backgroundColor = [UIColor colorWithRed:205 / 255.0 green:92 / 255.0  blue:92 / 255.0 alpha:0.8];
        
        
        
        self.sixImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, self.fourImageView.frame.origin.y + self.fourImageView.bounds.size.height + 5,  width, height)];
        self.sixImageView.image = [UIImage imageNamed:@"page"];
        self.sixImageView.tag = 105;
        self.sevenImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.fiveLabel.frame.origin.x,self.fiveLabel.frame.origin.y + self.oneImageView.bounds.size.height + 5,  2 *width + kP6Height(5), height * 2 + kP6Height(5))];
        self.sevenImageView.tag = 104;
        self.sevenImageView.image = [UIImage imageNamed:@"page"];
        self.eightImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, self.sixImageView.frame.origin.y + self.sixImageView.bounds.size.height + 5, width , height)];
        self.eightImageView.tag = 106;
        self.eightImageView.image = [UIImage imageNamed:@"page"];
        [self.contentView addSubview: self.oneImageView];
        [self.contentView addSubview: self.twoImageView];
        [self.contentView addSubview: self.threeImageView];
        [self.contentView addSubview: self.fourImageView];
        [self.contentView addSubview: self.fiveLabel];
        [self.contentView addSubview: self.sixImageView];
        [self.contentView addSubview: self.sevenImageView];
        [self.contentView addSubview: self.eightImageView];
        
        
        
        
        
        
    }
  
    return self;
}

- (void)setModel:(NSMutableArray *)array {
    if (array.count != 0) {

        for (int i = 0 ; i < 7; i++) {
            if (i < array.count) {
               CarModel *model = array[i];
            UIImageView *imageView = (UIImageView *)[self.contentView viewWithTag:100 + i];
            [imageView sd_setImageWithURL:[NSURL URLWithString:model.array.firstObject] placeholderImage:[UIImage imageNamed:@"8-1"]]; 
            }
            else{
                UIImageView *imageView = (UIImageView *)[self.contentView viewWithTag:100 + i];
                imageView.image = [UIImage imageNamed:@"page"];
                
            }
            
            
        }
        
    }

}

- (void)addTarget:(id)target action:(SEL)action{
    
    for (int i = 0; i < 7; i ++) {
        UIImageView *imageView = (UIImageView *)[self.contentView viewWithTag:100 + i];
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:target action:action];
        [imageView addGestureRecognizer:tap];
        
    }
    
    
}



@end
